import { Injectable, Logger } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { ConfigService } from '@nestjs/config';
import { BaseService } from '@wwjCommon/base/base.service';
import { CacheService } from '@wwjCommon/cache/cache.service';
import { LoggingService } from '@wwjCommon/logging/logging.service';
import { UploadService } from '@wwjVendor/upload/upload.service';
import { PayService } from '@wwjVendor/pay/pay.service';
import { SmsService } from '@wwjVendor/sms/sms.service';
import { NoticeService } from '@wwjVendor/notice/notice.service';

@Injectable()
export class AddressService extends BaseService<any> {
  private readonly logger = new Logger(AddressService.name);

  constructor(
    @InjectRepository(Object)
    protected readonly repository: Repository<any>,
    private readonly cacheService: CacheService,
    private readonly configService: ConfigService,
    private readonly loggingService: LoggingService,
    private readonly uploadService: UploadService,
    private readonly payService: PayService,
    private readonly smsService: SmsService,
    private readonly noticeService: NoticeService,
  ) {
    super(repository);
  }

  /**
   * getList
   * 对应 PHP: AddressService_api::getList()
   * 逻辑类型: undefined - undefined
   */
  async getList(where: any[]) {
    // 基于PHP真实逻辑: getList
    // PHP原文: $where['member_id'] = $this->member_id;         $where['site_id'] = $this->site_id;         return ( new CoreMemberAddressService() )->getList($where)...
where.member_id = this.member_id;
        where.site_id = this.site_id;
        return ( this.coreMemberAddressService ).getList(where);
    }

    /**
     * 获取会员收货地址信息
     * @param int id
     * @return */
    async getInfo(int id)
    {
        data.member_id = this.member_id;
        data.site_id = this.site_id;
        return ( this.coreMemberAddressService ).getInfo(id, data);
    }

    /**
     * 添加会员收货地址
     * @param data
     * @return mixed
     */
    async add(data)
    {
        data.member_id = this.member_id;
        data.site_id = this.site_id;
        return ( this.coreMemberAddressService ).add(data);
    }

    /**
     * 会员收货地址编辑
     * @param int id
     * @param data
     * @return bool
     */
    async edit(int id, data)
    {
        data.member_id = this.member_id;
        data.site_id = this.site_id;
        return ( this.coreMemberAddressService ).edit(id, data);
    }

    /**
     * 删除会员收货地址
     * @param int id
     * @return bool
     */
    async del(int id)
    {
        const model = this.model.where([ ['id', '=', id], ['site_id', '=', this.site_id], ['member_id', '=', this.member_id ) )).find(];
        const res = model.delete();
        return res;
    }

}
  }

  /**
   * getInfo
   * 对应 PHP: AddressService_api::getInfo()
   * 逻辑类型: undefined - undefined
   */
  async getInfo(id: number) {
    // 基于PHP真实逻辑: getInfo
    // PHP原文: $data['member_id'] = $this->member_id;         $data['site_id'] = $this->site_id;         return ( new CoreMemberAddressService() )->getInfo($id, $dat...
data.member_id = this.member_id;
        data.site_id = this.site_id;
        return ( this.coreMemberAddressService ).getInfo(id, data);
    }

    /**
     * 添加会员收货地址
     * @param data
     * @return mixed
     */
    async add(data)
    {
        data.member_id = this.member_id;
        data.site_id = this.site_id;
        return ( this.coreMemberAddressService ).add(data);
    }

    /**
     * 会员收货地址编辑
     * @param int id
     * @param data
     * @return bool
     */
    async edit(int id, data)
    {
        data.member_id = this.member_id;
        data.site_id = this.site_id;
        return ( this.coreMemberAddressService ).edit(id, data);
    }

    /**
     * 删除会员收货地址
     * @param int id
     * @return bool
     */
    async del(int id)
    {
        const model = this.model.where([ ['id', '=', id], ['site_id', '=', this.site_id], ['member_id', '=', this.member_id ) )).find(];
        const res = model.delete();
        return res;
    }

}
  }

  /**
   * add
   * 对应 PHP: AddressService_api::add()
   * 逻辑类型: undefined - undefined
   */
  async add(data: any[]) {
    // 基于PHP真实逻辑: add
    // PHP原文: $data['member_id'] = $this->member_id;         $data['site_id'] = $this->site_id;         return ( new CoreMemberAddressService() )->add($data);     }...
data.member_id = this.member_id;
        data.site_id = this.site_id;
        return ( this.coreMemberAddressService ).add(data);
    }

    /**
     * 会员收货地址编辑
     * @param int id
     * @param data
     * @return bool
     */
    async edit(int id, data)
    {
        data.member_id = this.member_id;
        data.site_id = this.site_id;
        return ( this.coreMemberAddressService ).edit(id, data);
    }

    /**
     * 删除会员收货地址
     * @param int id
     * @return bool
     */
    async del(int id)
    {
        const model = this.model.where([ ['id', '=', id], ['site_id', '=', this.site_id], ['member_id', '=', this.member_id ) )).find(];
        const res = model.delete();
        return res;
    }

}
  }

  /**
   * edit
   * 对应 PHP: AddressService_api::edit()
   * 逻辑类型: undefined - undefined
   */
  async edit(id: any[], data: any[]) {
    // 基于PHP真实逻辑: edit
    // PHP原文: $data['member_id'] = $this->member_id;         $data['site_id'] = $this->site_id;         return ( new CoreMemberAddressService() )->edit($id, $data);...
data.member_id = this.member_id;
        data.site_id = this.site_id;
        return ( this.coreMemberAddressService ).edit(id, data);
    }

    /**
     * 删除会员收货地址
     * @param int id
     * @return bool
     */
    async del(int id)
    {
        const model = this.model.where([ ['id', '=', id], ['site_id', '=', this.site_id], ['member_id', '=', this.member_id ) )).find(];
        const res = model.delete();
        return res;
    }

}
  }

  /**
   * del
   * 对应 PHP: AddressService_api::del()
   * 逻辑类型: undefined - undefined
   */
  async del(id: number) {
    // 基于PHP真实逻辑: del
    // PHP原文: $model = $this->model->where([ ['id', '=', $id], ['site_id', '=', $this->site_id], ['member_id', '=', $this->member_id ] ])->find();         $res = $m...
const model = this.model.where([ ['id', '=', id], ['site_id', '=', this.site_id], ['member_id', '=', this.member_id ) )).find(];
        const res = model.delete();
        return res;
    }

}
  }
}
